package com.chixing.day02_switch_case;

public class SortUtil {

    /**
     * 冒泡排序
     * @param arr
     * @return
     */
    public static int[] bubbleSort(int[] arr){
        for (int i = 0; i < arr.length-1; i++) {
            for (int j = 0; j < arr.length-i-1; j++) {
                if(arr[j]>arr[j+1]){
                    int temp=arr[j];
                    arr[j]=arr[j+1];
                    arr[j+1]=temp;
                }
            }
        }
        return arr;
    }

    /**
     * 快速排序
     */
    public static int[] quickSort(int[] arr,int low,int high){
        if(low <high){
            int i = low;
            int j = high;
            int temp = arr[low];
            while (i <j){
                while (i <j && arr[j]>temp)
                    j--;
                arr[i]=arr[j];
                while (i <j && arr[i]<=temp)
                    i++;
                arr[j]=arr[i];
            }
            arr[i]=temp;
            quickSort(arr,low,i-1);
            quickSort(arr,i+1,high);
        }
        return arr;
    }
}
